package com.ssy.lingxi.product.controller.feign;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.ssy.lingxi.common.constant.Constants;
import com.ssy.lingxi.common.constant.product.CommodityStatusEnum;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.product.api.model.request.CommodityCreditScore;
import com.ssy.lingxi.product.api.model.request.CommoditySold;
import com.ssy.lingxi.product.api.model.request.MemberRequest;
import com.ssy.lingxi.product.api.model.request.SimpleIdListRequest;
import com.ssy.lingxi.product.api.model.request.channelCommodity.ChannelCommodityQueryRequest;
import com.ssy.lingxi.product.api.model.request.commodity.CommodityQueryRequest;
import com.ssy.lingxi.product.api.model.request.feign.CommodityNameRequest;
import com.ssy.lingxi.product.api.model.request.feign.CommodityPriceRequest;
import com.ssy.lingxi.product.api.model.request.feign.CommodityPublishRequest;
import com.ssy.lingxi.product.api.model.request.feign.OffPublishCommodityRequest;
import com.ssy.lingxi.product.api.model.response.BrandResponse;
import com.ssy.lingxi.product.api.model.response.channelCommodity.ChannelCommodityESResponse;
import com.ssy.lingxi.product.api.model.response.commodity.*;
import com.ssy.lingxi.product.api.model.response.feign.CommodityPriceResponse;
import com.ssy.lingxi.product.api.model.response.feign.CommoditySkuStockResponse;
import com.ssy.lingxi.product.api.model.response.store.StoreCommodityResponse;
import com.ssy.lingxi.product.api.model.response.store.StoreResponse;
import com.ssy.lingxi.product.entity.Brand;
import com.ssy.lingxi.product.entity.channelCommodity.ChannelCommodity;
import com.ssy.lingxi.product.entity.commodity.Commodity;
import com.ssy.lingxi.product.entity.commodity.CommodityGoodsAttribute;
import com.ssy.lingxi.product.entity.commodity.CommodityUnitPriceAndPic;
import com.ssy.lingxi.product.entity.customer.CustomerCategory;
import com.ssy.lingxi.product.service.IBrandService;
import com.ssy.lingxi.product.service.IChannelCommodityService;
import com.ssy.lingxi.product.service.ICommodityService;
import com.ssy.lingxi.product.service.IGoodsService;
import com.ssy.lingxi.product.service.customer.ICustomerCategoryService;
import com.ssy.lingxi.product.service.es.ISyncEsCommodityService;
import org.apache.commons.lang.StringUtils;
import org.modelmapper.TypeToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 商品管理类
 *
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/28
 */
@RestController
@RequestMapping("/product/feign/commodity")
public class CommodityFeignController extends BaseController {

    @Resource
    private ICommodityService commodityService;

    @Resource
    private IChannelCommodityService channelCommodityService;

    @Resource
    private ICustomerCategoryService customerCategoryService;

    @Resource
    private IBrandService brandService;

    @Resource
    private IGoodsService goodsService;

    @Resource
    private ISyncEsCommodityService syncEsCommodityService;

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    /**
     * 查询商品是否用到运费模板
     *
     * @param id 运费模板id
     * @return
     */
    @RequestMapping(value = "/getCommodityUseTemplate", method = RequestMethod.GET)
    public Wrapper<Boolean> getCommodityUseTemplate(@RequestParam("id") Long id) {
        return Wrapper.success(commodityService.getCommodityUseTemplate(id));
    }

    /**
     * 查询商品是否用到发货地址
     *
     * @param id 发货地址id
     * @return
     */
    @RequestMapping(value = "/getCommodityUseSendAddress", method = RequestMethod.GET)
    public Wrapper<Boolean> getCommodityUseSendAddress(@RequestParam("id") Long id) {
        return Wrapper.success(commodityService.getCommodityUseSendAddress(id));
    }

    /**
     * 查询商品是否用到物流公司
     *
     * @param id 物流公司id
     * @return
     */
    @RequestMapping(value = "/getCommodityUseCompany", method = RequestMethod.GET)
    public Wrapper<Boolean> getCommodityUseCompany(@RequestParam("id") Long id) {
        return Wrapper.success(commodityService.getCommodityUseCompany(id));
    }

    /**
     * 查询商品是否用到单位
     *
     * @param id 单位id
     * @return
     */
    @RequestMapping(value = "/getCommodityUseUnit", method = RequestMethod.GET)
    public Wrapper<Boolean> getCommodityUseUnit(@RequestParam("id") Long id) {
        return Wrapper.success(commodityService.getCommodityUseUnit(id));
    }

    /**
     * 批量查询商品价格
     *
     * @param commodityPriceRequest
     * @return
     */
    @RequestMapping(value = "/getCommodityPriceBatch", method = RequestMethod.POST)
    public Map<Long, Map<String, Double>> getCommodityPriceBatch(@RequestBody @Valid CommodityPriceRequest commodityPriceRequest) {
        Long shopId = commodityPriceRequest.getShopId();
        Integer commodityType = commodityPriceRequest.getCommodityType();
        List<Long> commoditySkuIdList = commodityPriceRequest.getCommoditySkuIdList();
        Long memberId = commodityPriceRequest.getMemberId();
        Long memberRoleId = commodityPriceRequest.getMemberRoleId();
        if(commodityType == 1){
            return commodityService.getCommodityPriceBatch(shopId, commoditySkuIdList, memberId, memberRoleId);
        }else if(commodityType == 2){
            return channelCommodityService.getCommodityPriceBatch(commoditySkuIdList);
        }else{
            return null;
        }
    }

    /**
     * 批量查询商品价格和是否允许使用会员权益
     *
     * @param commodityPriceRequest
     * @return
     */
    @RequestMapping(value = "/getCommodityPriceAndMemberPriceBatch", method = RequestMethod.POST)
    public Map<Long, CommodityPriceResponse> getCommodityPriceAndMemberPriceBatch(@RequestBody @Valid CommodityPriceRequest commodityPriceRequest) {
        Long shopId = commodityPriceRequest.getShopId();
        Integer commodityType = commodityPriceRequest.getCommodityType();
        List<Long> commoditySkuIdList = commodityPriceRequest.getCommoditySkuIdList();
        Long memberId = commodityPriceRequest.getMemberId();
        Long memberRoleId = commodityPriceRequest.getMemberRoleId();
        if(commodityType == 1){
            return commodityService.getCommodityPriceAndMemberPriceBatch(shopId, commoditySkuIdList, memberId, memberRoleId);
        }else if(commodityType == 2){
            return channelCommodityService.getCommodityPriceAndMemberPriceBatch(commoditySkuIdList);
        }else{
            return null;
        }
    }

    /**
     * 查询商品信息列表--订单校验商品信息
     *
     * @param commodityPriceRequest 查询条件实体
     * @return
     */
    @RequestMapping(value = "/getCommodityListByOrder", method = RequestMethod.POST)
    public List<CommodityOrderResponse> getCommodityListByOrder(@RequestBody @Valid CommodityPriceRequest commodityPriceRequest) {
        Integer commodityType = commodityPriceRequest.getCommodityType();
        if(commodityType == 1){
            return commodityService.getCommodityListByOrder(commodityPriceRequest);
        }else if(commodityType == 2){
            return channelCommodityService.getCommodityListByOrder(commodityPriceRequest);
        }else{
            return null;
        }
    }

    /**
     * 通过会员id查询会员品类和商品图片
     *
     * @param simpleIdListRequest
     * @return
     */
    @RequestMapping(value = "/getCommodityAndCategoryByMemberId", method = RequestMethod.POST)
    public Map<Long, StoreResponse> getCommodityAndCategoryByMemberId(@RequestBody SimpleIdListRequest simpleIdListRequest) {
        List<Long> memberIdList = simpleIdListRequest.getIdList();
        List<CustomerCategory> customerCategoryList = customerCategoryService.getCustomerCategoryByMemberId(memberIdList);
        Map<Long, StoreResponse> map = new HashMap<>();
        memberIdList.forEach(memberId -> {
            StoreResponse storeResponse = new StoreResponse();
            String customerCategoryName = customerCategoryList.stream().filter(customerCategory -> customerCategory.getMemberId().equals(memberId)).map(CustomerCategory::getName).collect(Collectors.joining(" | "));

            PageVO pageVO = new PageVO();
            pageVO.setCurrent(1);
            pageVO.setPageSize(2);
            List<Integer> statusList = new ArrayList<>();
            statusList.add(CommodityStatusEnum.On_Shelf.getCode());
            CommodityQueryRequest commodityQueryRequest = new CommodityQueryRequest();
            commodityQueryRequest.setMemberId(memberId);
            commodityQueryRequest.setStatusList(statusList);
            Page<Commodity> commodityList = commodityService.getCommodityList(pageVO, commodityQueryRequest);
            List<StoreCommodityResponse> storeCommodityList = commodityList.stream().map(commodity -> {
                List<CommodityUnitPriceAndPic> unitPriceAndPicList = commodity.getUnitPriceAndPicList();
                StoreCommodityResponse storeCommodityResponse = new StoreCommodityResponse();
                storeCommodityResponse.setId(commodity.getId());
                storeCommodityResponse.setMainPic(commodity.getMainPic());
                storeCommodityResponse.setUnitPrice(unitPriceAndPicList.size() > 0 ? unitPriceAndPicList.get(0).getUnitPrice() : new HashMap<>());
                return storeCommodityResponse;
            }).collect(Collectors.toList());

            storeResponse.setCustomerCategoryName(customerCategoryName);
            storeResponse.setCommodityList(storeCommodityList);
            map.put(memberId, storeResponse);
        });
        return map;
    }

    /**
     * 通过会员id和会员角色id查询会员品类和商品图片
     *
     * @param memberRequestList
     * @return
     */
    @RequestMapping(value = "/getCommodityAndCategoryByMemberIdAndMemberRoleId", method = RequestMethod.POST)
    public Map<String, StoreResponse> getCommodityAndCategoryByMemberIdAndMemberRoleId(@RequestBody List<MemberRequest> memberRequestList) {
        List<Long> memberIdList = memberRequestList.stream().map(MemberRequest::getMemberId).collect(Collectors.toList());
        List<Long> memberRoleIdList = memberRequestList.stream().map(MemberRequest::getMemberRoleId).collect(Collectors.toList());
        List<CustomerCategory> customerCategoryList = customerCategoryService.getCustomerCategoryByMemberIdAndMemberRoleId(memberIdList, memberRoleIdList);
        Map<String, StoreResponse> map = new HashMap<>();
        memberRequestList.forEach(memberRequest -> {
            Long memberId = memberRequest.getMemberId();
            Long memberRoleId = memberRequest.getMemberRoleId();
            StoreResponse storeResponse = new StoreResponse();
            String customerCategoryName = customerCategoryList.stream().filter(customerCategory -> customerCategory.getMemberId().equals(memberId) && customerCategory.getMemberRoleId().equals(memberRoleId) && customerCategory.getLevel() == 1).map(CustomerCategory::getName).collect(Collectors.joining(" | "));

            PageVO pageVO = new PageVO();
            pageVO.setCurrent(1);
            pageVO.setPageSize(2);
            List<Integer> statusList = new ArrayList<>();
            statusList.add(CommodityStatusEnum.On_Shelf.getCode());
            CommodityQueryRequest commodityQueryRequest = new CommodityQueryRequest();
            commodityQueryRequest.setMemberId(memberId);
            commodityQueryRequest.setMemberRoleId(memberRoleId);
            commodityQueryRequest.setStatusList(statusList);
            Page<Commodity> commodityList = commodityService.getCommodityList(pageVO, commodityQueryRequest);
            List<StoreCommodityResponse> storeCommodityList = commodityList.stream().map(commodity -> {
                if (!CollectionUtils.isEmpty(commodity.getUnitPriceAndPicList())) {
                    CommodityUnitPriceAndPic commodityUnitPriceAndPic = new ArrayList<>(commodity.getUnitPriceAndPicList()).get(0);
                    StoreCommodityResponse storeCommodityResponse = new StoreCommodityResponse();
                    storeCommodityResponse.setId(commodity.getId());
                    storeCommodityResponse.setMainPic(commodity.getMainPic());
                    storeCommodityResponse.setUnitPrice(commodityUnitPriceAndPic.getUnitPrice());
                    return storeCommodityResponse;
                } else {
                    return new StoreCommodityResponse();
                }
            }).collect(Collectors.toList());

            storeResponse.setCustomerCategoryName(customerCategoryName);
            storeResponse.setCommodityList(storeCommodityList);
            map.put(memberId + "-" + memberRoleId, storeResponse);
        });
        return map;
    }

    /**
     * 查询商品信息
     *
     * @param id 商品id
     * @return
     */
    @RequestMapping(value = "/getCommodity", method = RequestMethod.GET)
    public CommodityDetailResponse getCommodity(@RequestParam("id") Long id) {
        Commodity commodity = commodityService.getCommodity(id);
        if(commodity != null){
            return this.modelMapper.map(commodity, CommodityDetailResponse.class);
        }
        return null;
    }

    /**
     * 查询商品sku规格名称
     *
     * @param id 商品skuId
     * @return
     */
    @RequestMapping(value = "/getCommodityBySkuId", method = RequestMethod.GET)
    public CommodityBaseResponse getCommodityBySkuId(@RequestParam("id") Long id) {
        CommodityUnitPriceAndPic commodityUnitPriceAndPic = commodityService.getCommodityBySkuId(id);
        if(commodityUnitPriceAndPic != null){
            Commodity commodity = commodityUnitPriceAndPic.getCommodity();

            CommodityBaseResponse commodityBaseResponse = new CommodityBaseResponse();
            commodityBaseResponse.setId(commodity.getId());
            commodityBaseResponse.setBrand(commodity.getBrand() == null ? "" : commodity.getBrand().getName());
            commodityBaseResponse.setCode(commodity.getCode());
            commodityBaseResponse.setName(commodity.getName());

            //查询品类全称
            CustomerCategory customerCategory = commodity.getCustomerCategory();
            if(customerCategory != null){
                commodityBaseResponse.setCustomerCategory(customerCategoryService.getFullNameByFullId(customerCategory.getFullId()));
            }

            //商品属性
            List<CommodityGoodsAttribute> attributeAndValueList = commodityUnitPriceAndPic.getAttributeAndValueList();
            String attribute = StringUtils.join(attributeAndValueList.stream().sorted(Comparator.comparing(CommodityGoodsAttribute::getId).reversed()).map(commodityGoodsAttribute -> commodityGoodsAttribute.getCustomerAttributeValue().getValue()).toArray(String[]::new), Constants.COMMODITY_NAME_SPLIT_STR);
            commodityBaseResponse.setCommodityAttribute(attribute);

            return commodityBaseResponse;
        }else{
            throw new BusinessException(ResponseCode.PRODUCT_COMMODITY_NOT_EXIST);
        }
    }

    /**
     * 查询所有已上架的商品
     *
     * @param current  当前页码
     * @param pageSize 每页数量
     * @return
     */
    @RequestMapping(value = "/getAllOnShelfCommodity", method = RequestMethod.GET)
    public PageData<CommodityDetailResponse> getAllOnShelfCommodity(@RequestParam("current") Integer current, @RequestParam("pageSize") Integer pageSize) {
        PageVO pageVO = new PageVO();
        pageVO.setCurrent(current);
        pageVO.setPageSize(pageSize);
        CommodityQueryRequest commodityQueryRequest = new CommodityQueryRequest();
        List<Integer> statusList = new ArrayList<>();
        statusList.add(CommodityStatusEnum.On_Shelf.getCode());
        commodityQueryRequest.setStatusList(statusList);
        Page<Commodity> result = commodityService.getCommodityList(pageVO, commodityQueryRequest);
        List<CommodityDetailResponse> resultList = this.modelMapper.map(result.getContent(), new TypeToken<List<CommodityDetailResponse>>() {
        }.getType());

        return new PageData<>(result.getTotalElements(), resultList);
    }

    /**
     * 查询渠道商品信息
     * @param id 渠道商品id
     * @return
     */
    @RequestMapping(value = "/getChannelCommodity", method = RequestMethod.GET)
    public ChannelCommodityESResponse getChannelCommodity(@RequestParam("id") Long id) {
        ChannelCommodity channelCommodity = channelCommodityService.getChannelCommodityById(id);
        if(channelCommodity != null){
            return this.modelMapper.map(channelCommodity, ChannelCommodityESResponse.class);
        }
        return null;
    }

    /**
     * 查询所有已上架的渠道商品
     *
     * @param current  当前页码
     * @param pageSize 每页数量
     * @return
     */
    @RequestMapping(value = "/getAllOnShelfChannelCommodity", method = RequestMethod.GET)
    public PageData<ChannelCommodityESResponse> getAllOnShelfChannelCommodity(@RequestParam("current") Integer current, @RequestParam("pageSize") Integer pageSize) {
        PageVO pageVO = new PageVO();
        pageVO.setCurrent(current);
        pageVO.setPageSize(pageSize);
        ChannelCommodityQueryRequest commodityQueryRequest = new ChannelCommodityQueryRequest();
        Page<ChannelCommodity> result = channelCommodityService.getChannelCommodityList(pageVO, commodityQueryRequest);
        List<ChannelCommodityESResponse> resultList = this.modelMapper.map(result.getContent(), new TypeToken<List<ChannelCommodityESResponse>>() {
        }.getType());

        return new PageData<>(result.getTotalElements(), resultList);
    }

    /**
     * 下架某个会员的所有商品
     *
     * @return
     */
    @RequestMapping(value = "/offPublishAllCommodity", method = RequestMethod.POST)
    public Wrapper<Boolean> offPublishAllCommodity(@RequestBody OffPublishCommodityRequest offPublishCommodityRequest) {
        Long memberId = offPublishCommodityRequest.getMemberId();
        Long memberRoleId = offPublishCommodityRequest.getMemberRoleId();
        Boolean isMember = offPublishCommodityRequest.getIsMember();
        if(isMember){
            return Wrapper.success(commodityService.offPublishAllCommodity(memberId, memberRoleId));
        }else{
            return Wrapper.success(channelCommodityService.offPublishAllCommodity(memberId, memberRoleId));
        }
    }

    /**
     * 查询商品sku对应的库存
     *
     * @param commodityPriceRequest
     * @return
     */
    @RequestMapping(value = "/getCommoditySkuStock", method = RequestMethod.POST)
    public Wrapper<List<CommoditySkuStockResponse>> getCommoditySkuStock(@RequestBody CommodityPriceRequest commodityPriceRequest) {
        Long memberId = commodityPriceRequest.getMemberId();
        Long memberRoleId = commodityPriceRequest.getMemberRoleId();
        Long shopId = commodityPriceRequest.getShopId();
        List<Long> commoditySkuIdList = commodityPriceRequest.getCommoditySkuIdList();
        Integer commodityType = commodityPriceRequest.getCommodityType();
        if(commodityType == 1){
            List<CommoditySkuStockResponse> commoditySkuStockResponseList = commodityService.getCommoditySkuStock(memberId, memberRoleId, shopId, commoditySkuIdList);
            return Wrapper.success(commoditySkuStockResponseList);
        }else{
            return Wrapper.success(null);
        }
    }

    /**
     * 查询品类信息
     *
     * @param idList 品类id
     * @return
     */
    @RequestMapping(value = "/getCustomerCategoryById", method = RequestMethod.POST)
    public Wrapper<List<CustomerCategoryResponse>> getCustomerCategoryById(@RequestBody List<Long> idList) {
        List<CustomerCategory> customerCategoryList = customerCategoryService.getCustomerCategoryByIdList(idList);
        List<CustomerCategoryResponse> customerCategoryResponseList = customerCategoryList.stream().map(customerCategory -> BeanUtil.copyProperties(customerCategory, CustomerCategoryResponse.class)).collect(Collectors.toList());
        return Wrapper.success(customerCategoryResponseList);
    }

    /**
     * 查询品牌信息
     *
     * @param idList 品牌id
     * @return
     */
    @RequestMapping(value = "/getBrandById", method = RequestMethod.POST)
    public Wrapper<List<BrandResponse>> getBrandById(@RequestBody List<Long> idList) {
        List<Brand> brandList = brandService.getBrandByIdList(idList);
        List<BrandResponse> brandResponseList = brandList.stream().map(brand -> BeanUtil.copyProperties(brand, BrandResponse.class)).collect(Collectors.toList());
        return Wrapper.success(brandResponseList);
    }

    /**
     * 查询商品列表--通过会员商品sku集合
     *
     * @param commoditySkuIdList 查询条件实体
     * @return
     */
    @RequestMapping(value = "/getCommodityByCommoditySkuIdList", method = RequestMethod.POST)
    public Wrapper<List<CommodityGoodsResponse>> getCommodityByCommoditySkuIdList(@RequestBody List<Long> commoditySkuIdList) {
        return Wrapper.success(commodityService.getCommodityByCommoditySkuIdList(commoditySkuIdList));
    }

    /**
     * 查询上游供应会员商品列表--通过会员商品sku集合
     *
     * @param commoditySkuIdList 查询条件实体
     * @return
     */
    @RequestMapping(value = "/getUpperCommodityByCommoditySkuIdList", method = RequestMethod.POST)
    public Wrapper<List<UpperCommodityResponse>> getUpperCommodityByCommoditySkuIdList(@RequestBody List<Long> commoditySkuIdList) {
        return Wrapper.success(commodityService.getUpperCommodityByCommoditySkuIdList(commoditySkuIdList));
    }

    /**
     * 判断商品是否上架
     * @param commodityPublishRequest 查询条件实体
     * @return
     */
    @RequestMapping(value = "/getCommodityIsPublish", method = RequestMethod.POST)
    public Wrapper<String> getCommodityIsPublish(@RequestBody CommodityPublishRequest commodityPublishRequest) {
        Long shopId = commodityPublishRequest.getShopId();
        Boolean isChannelCommodity = commodityPublishRequest.getIsChannelCommodity();
        List<CommodityNameRequest> commodityList = commodityPublishRequest.getCommodityList();
        //判断商品是否已上架
        if(isChannelCommodity){
            return Wrapper.fail(channelCommodityService.getCommodityIsPublish(shopId, commodityList));
        }else{
            return Wrapper.fail(commodityService.getCommodityIsPublish(shopId, commodityList));
        }
    }

    /**
     * 判断商品是否上架
     * @param commodityPublishRequest 查询条件实体
     * @return 上架的商品id数组
     */
    @RequestMapping(value = "/getCommodityListByIsPublish", method = RequestMethod.POST)
    public Wrapper<List<Long>> getCommodityListByIsPublish(@RequestBody CommodityPublishRequest commodityPublishRequest) {
        Long shopId = commodityPublishRequest.getShopId();
        Boolean isChannelCommodity = commodityPublishRequest.getIsChannelCommodity();
        List<CommodityNameRequest> commodityList = commodityPublishRequest.getCommodityList();
        //判断商品是否已上架
        if (isChannelCommodity) {
            return Wrapper.success(channelCommodityService.getCommodityListByIsPublish(shopId, commodityList));
        } else {
            return Wrapper.success(commodityService.getCommodityListByIsPublish(shopId, commodityList));
        }
    }

    /**
     * 更新会员商品已售数量
     */
    @RequestMapping(value = "/updateCommoditySold", method = RequestMethod.POST)
    public Wrapper<Boolean> updateCommoditySold(@RequestBody CommoditySold commoditySold){
        log.info("更新会员商品已售数量:参数{}", JSONUtil.toJsonStr(commoditySold));
        //更新商品已售
        syncEsCommodityService.updateCommoditySold(commoditySold);
        //更新常购清单
        syncEsCommodityService.updateOftenBuyCommodity(commoditySold);
        return Wrapper.success(true);
    }

    /**
     * 更新渠道商品已售数量
     */
    @RequestMapping(value = "/updateChannelCommoditySold", method = RequestMethod.POST)
    public Wrapper<Boolean> updateChannelCommoditySold(@RequestBody CommoditySold commoditySold){
        log.info("更新渠道商品已售数量:参数{}", JSONUtil.toJsonStr(commoditySold));
        return Wrapper.success(syncEsCommodityService.updateChannelCommoditySold(commoditySold));
    }

    /**
     * 更新商品对应的店铺积分
     */
    @RequestMapping(value = "/updateCommodityCreditScore", method = RequestMethod.POST)
    public Wrapper<Boolean> updateCommodityCreditScore(@RequestBody CommodityCreditScore commodityCreditScore){
        return Wrapper.success(syncEsCommodityService.updateCommodityCreditScore(commodityCreditScore));
    }

    /**
     * 通过商品skuId数组查询对应的商品一级品类id
     *
     * @param simpleIdListRequest 商品skuId数组
     */
    @RequestMapping(value = "/getCommodityFirstCategoryIdList", method = RequestMethod.POST)
    public Wrapper<List<CommoditySkuIdAndFirstCategoryIdResponse>> getCommodityFirstCategoryIdList(@RequestBody @Valid SimpleIdListRequest simpleIdListRequest) {
        return Wrapper.success(commodityService.getCommodityFirstCategoryIdList(simpleIdListRequest.getIdList()));
    }

    /**
     * 通过货品Id数组查询对应的货品一级品类id
     *
     * @param simpleIdListRequest 货品Id数组
     */
    @RequestMapping(value = "/getGoodsFirstCategoryIdList", method = RequestMethod.POST)
    public Wrapper<List<GoodsIdAndFirstCategoryIdResponse>> getGoodsFirstCategoryIdList(@RequestBody @Valid SimpleIdListRequest simpleIdListRequest) {
        return Wrapper.success(goodsService.getGoodsFirstCategoryIdList(simpleIdListRequest.getIdList()));
    }
}
